package Time918;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import util.Common;

public class Subjectdao {
	public List<Subject> get(int gradeid) {
		List<Subject> sl = new ArrayList<Subject>();
		String sql = "select * from `subject` where gradeid=?";
		Connection con = Common.getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;

		Subject s = null;
		try {
			ps = con.prepareStatement(sql);
			ps.setInt(1, gradeid);
			rs = ps.executeQuery();
			while (rs.next()) {
				s = new Subject();
				s.setId(rs.getInt("id"));
				s.setSubjectname(rs.getString("subjectname"));
				s.setClasshour(rs.getInt("classhour"));
				s.setGradeid(gradeid);
				sl.add(s);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Common.close(con, ps, rs);
		}

		return sl;
	}
}
